<template>
  <div class="divBox relative">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <!-- <el-tabs
          v-model="tableFrom.type"
          @tab-click="seachList"
          v-if="checkPermi(['admin:product:tabs:headers'])"
        >
          <el-tab-pane
            :label="item.name + '(' + item.count + ')'"
            :name="item.type.toString()"
            v-for="(item, index) in headeNum"
            :key="index"
          />
        </el-tabs> -->
        <div class="container mt-1">
          <el-form inline size="small" label-width="100px">
            <el-form-item label="商品名称：">
              <el-input
                v-model="tableFrom.storeName"
                placeholder="请输入商品名称"
                class="selWidth"
                size="small"
                clearable
              />
            </el-form-item>
            <!-- <el-form-item label="数量：">
              <el-input
                v-model="tableFrom.goodsName"
                placeholder="请输入商品数量"
                class="selWidth"
                size="small"
                clearable
                type="number"
              />
            </el-form-item> -->
            <el-form-item label="商品所有人：">
              <el-input
                v-model="tableFrom.phone"
                placeholder="请输入商品名称"
                class="selWidth"
                size="small"
                clearable
              />
            </el-form-item>
            <el-form-item label="状态：">
              <el-select
                v-model="tableFrom.isShow"
                style="width: 200px"
                placeholder="请选择状态"
              >
                <el-option label="下架" :value="1"> </el-option>
                <el-option label="上架" :value="0"> </el-option>
              </el-select>
            </el-form-item>
            <!-- <el-form-item label="时间段：">
              <el-time-picker
                v-model="tableFrom.time"
                style="width: 200px"
                placeholder="选择时间点"
              >
              </el-time-picker>
            </el-form-item> -->
            <el-form-item>
              <el-button
                type="primary"
                @click="seachList"
                size="small"
                v-hasPermi="['admin:product:list']"
              >
                搜索
              </el-button>
            </el-form-item>
          </el-form>
        </div>
        <router-link :to="{ path: '/store/Wholesale/creatProduct' }">
          <el-button
            size="small"
            type="primary"
            class="mr10"
            v-hasPermi="['admin:wholesale:save']"
            >添加商品</el-button
          >
        </router-link>
        <!-- <el-button
          size="small"
          type="success"
          class="mr10"
          @click="handleRestore"
          v-hasPermi="['admin:product:save']"
          >删除</el-button
        >
        <el-button
          size="small"
          type="info"
          class="mr10"
          @click="onCopy"
          v-hasPermi="['admin:product:save']"
          >下架</el-button
        > -->
        <el-button
          size="small"
          icon="el-icon-upload2"
          @click="exports"
          v-hasPermi="['admin:export:excel:product']"
          >导入</el-button
        >
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="mini"
        :highlight-current-row="true"
        :header-cell-style="{ fontWeight: 'bold' }"
      >
        <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
        <el-table-column prop="id" label="ID" min-width="50" />
        <el-table-column
          label="商品名称"
          prop="storeName"
          min-width="300"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column label="商品图" min-width="80">
          <template slot-scope="scope">
            <div class="demo-image__preview">
              <el-image
                style="width: 36px; height: 36px"
                :src="scope.row.image"
                :preview-src-list="[scope.row.image]"
              />
            </div>
          </template>
        </el-table-column>

        <el-table-column
          prop="price"
          label="批发价格"
          min-width="90"
          align="center"
        />

        <el-table-column
          prop="stock"
          label="盒数"
          min-width="90"
          align="center"
        />
        <el-table-column
          prop="sales"
          label="销售价格"
          min-width="90"
          align="center"
        />
        <el-table-column
          prop="nickname"
          label="商品所有人"
          min-width="80"
          align="center"
        />

        <!-- <el-table-column label="添加时间" min-width="120" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.addTime | formatDate }}</span>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="交易状态" min-width="80" fixed="right">
          <template slot-scope="scope">
            <p v-if="scope.row.type == 1">等待买家付款</p>
            <p v-if="scope.row.type == 2">等待卖家收款确认</p>
            <p v-if="scope.row.type == 3">已提货</p>
            <p v-if="scope.row.type == 4">挂售中</p>
          </template>
        </el-table-column> -->
        <el-table-column
          label="操作"
          min-width="180"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <router-link
              :to="{
                path: '/store/Wholesale/creatProduct/' + scope.row.id,
              }"
            >
              <el-button
                type="text"
                size="small"
                class="mr10"
                v-hasPermi="['admin:product:update']"
                >编辑</el-button
              >
            </router-link>
            <el-button
              type="text"
              size="small"
              @click="onchangeIsShow(scope.row)"
              v-hasPermi="['admin:product:restore']"
              >下架</el-button
            >
            <el-button
              type="text"
              size="small"
              @click="handleDelete(scope.row.id, tableFrom.type)"
              v-hasPermi="['admin:product:delete']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <el-dialog
      title="复制淘宝、天猫、京东、苏宁"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="1200px"
      class="taoBaoModal"
      :before-close="handleClose"
    >
      <tao-bao v-if="dialogVisible" @handleCloseMod="handleCloseMod"></tao-bao>
    </el-dialog>
  </div>
</template>

<script>
import {
  productDeleteApi,
  categoryApi,
  putOnShellApi,
  offShellApi,
  productHeadersApi,
  restoreApi,
  productExcelApi,
} from "@/api/store";
import {
  productGetbiddingListApi,
  productBiddingBiddingDelete,
  productBiddingSellBiddingProduct,
} from "@/api/wholesale";
import { getToken } from "@/utils/auth";
import taoBao from "../taoBao";
import { checkPermi } from "@/utils/permission"; // 权限判断函数
export default {
  name: "WholesaleProductList",
  components: { taoBao },
  data() {
    return {
      props: {
        children: "child",
        label: "name",
        value: "id",
        emitPath: false,
      },
      // roterPre: roterPre,
      headeNum: [],
      listLoading: true,
      tableData: {
        data: [],
        total: 0,
      },
      tableFrom: {
        page: 1,
        limit: 20,
        cateId: "",
        keywords: "",
        type: "1",
      },
      categoryList: [],
      merCateList: [],
      objectUrl: process.env.VUE_APP_BASE_API,
      dialogVisible: false,
    };
  },
  mounted() {
    this.goodHeade();
    this.getList();
    this.getCategorySelect();
    this.checkedCities = this.$cache.local.has("goods_stroge")
      ? this.$cache.local.getJSON("goods_stroge")
      : this.checkedCities;
  },
  methods: {
    checkPermi,
    handleRestore(id) {
      this.$modalSure("恢复商品").then(() => {
        restoreApi(id).then((res) => {
          this.$message.success("操作成功");
          this.goodHeade();
          this.getList();
        });
      });
    },
    seachList() {
      this.tableFrom.page = 1;
      this.getList();
    },
    handleClose() {
      this.dialogVisible = false;
    },
    handleCloseMod(item) {
      this.dialogVisible = item;
      this.goodHeade();
      this.getList();
    },
    // 复制
    onCopy() {
      this.dialogVisible = true;
    },
    // 导出
    exports() {
      productExcelApi({
        cateId: this.tableFrom.cateId,
        keywords: this.tableFrom.keywords,
        type: this.tableFrom.type,
      }).then((res) => {
        window.location.href = res.fileName;
      });
    },
    // 获取商品表单头数量
    goodHeade() {
      productHeadersApi()
        .then((res) => {
          this.headeNum = res;
        })
        .catch((res) => {
          this.$message.error(res.message);
        });
    },
    // 商户分类；
    getCategorySelect() {
      categoryApi({ status: -1, type: 1 })
        .then((res) => {
          this.merCateList = res;
        })
        .catch((res) => {
          this.$message.error(res.message);
        });
    },
    // 列表
    getList() {
      this.listLoading = true;
      productGetbiddingListApi(this.tableFrom)
        .then((res) => {
          console.log("res", res);
          this.tableData.data = res.list;
          this.tableData.total = res.total;
          this.listLoading = false;
        })
        .catch((res) => {
          this.listLoading = false;
          this.$message.error(res.message);
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList();
    },
    // 删除
    handleDelete(id, type) {
      console.log(type);
      this.$modalSure(`删除 id 为 ${id} 的商品`).then(() => {
        const deleteFlag = type == 5 ? "delete" : "recycle";
        productBiddingBiddingDelete(id, deleteFlag).then(() => {
          this.$message.success("删除成功");
          this.getList();
          this.goodHeade();
        });
      });
    },
    onchangeIsShow(row) {
      productBiddingSellBiddingProduct(row.id)
        .then(() => {
          this.$message.success("下架成功");
          this.getList();
          this.goodHeade();
        })
        .catch(() => {
          row.isShow = !row.isShow;
        });
    },
  },
};
</script>

<style scoped lang="scss">
.el-table__body {
  width: 100%;
  table-layout: fixed !important;
}
// .taoBaoModal {
//   //  z-index: 3333 !important;
// }
.demo-table-expand {
  ::v-deep label {
    width: 82px;
  }
}
.demo-table-expand {
  ::v-deep .el-form-item__content {
    width: 77%;
  }
}
.selWidth {
  width: 200px !important;
}
.seachTiele {
  line-height: 30px;
}
.relative {
  position: relative;
}
</style>
